//
// Created by Administrator on 2018/11/6 0006.
//
#include <jni.h>
#include <GLES3/gl3.h>

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_renderCreate(JNIEnv *env, jobject obj) ;

JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_renderChagen(JNIEnv *env, jobject obj, jint width, jint height);

JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_drawFrame(JNIEnv *env, jobject obj);




#ifdef __cplusplus
};
#endif

GLuint textureId;

GLuint program;

GLubyte pixels[4 * 3] = {
        255,0,0,
        0,255,0,
        0,0,255,
        255,255,0
};

JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_renderCreate(JNIEnv *env, jobject obj) {
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

    program = glCreateProgram();
    glLinkProgram(program);

}


JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_renderChagen(JNIEnv *env, jobject obj, jint width, jint height){
    glViewport(0,0,width,height);
}

JNIEXPORT void JNICALL
Java_com_cloudream_glndk_Render_drawFrame(JNIEnv *env, jobject obj){
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(program);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);

    glGenTextures(1,&textureId);

    glBindTexture(GL_TEXTURE_2D,textureId);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,2,2,0,GL_RGB,GL_UNSIGNED_BYTE,pixels);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

}